package com.kanesoft.android.gdx.actors.fight;

import com.badlogic.gdx.Gdx;

public class AutoBehaviorFightLevelEasy extends AutoBehaviorFight {

    
    private CpuActions[] cpuActions;
    private float timeCounter;
    
    
    public AutoBehaviorFightLevelEasy(FightActorObject cpuPlayer, FightActorObject opponentPlayer) {
        super(cpuPlayer, opponentPlayer);
        initializeCpuActions();
    }
    
    
    public void initializeCpuActions() {
        CpuActions[] localCpuActions = {
          new CpuActions(cpuPlayer.waitingState, opponentPlayer.punchingState, 0, MIN_KICK_DISTANCE, cpuPlayer.walkingBackwardState),
          new CpuActions(cpuPlayer.walkingBackwardState, opponentPlayer.punchingState, 0, MIN_KICK_DISTANCE, cpuPlayer.jumpingState),
          new CpuActions(cpuPlayer.waitingState, opponentPlayer.waitingState, MAX_JUMP_DISTANCE, 1000f, cpuPlayer.throwFireball),
          
          new CpuActions(cpuPlayer.waitingState, opponentPlayer.throwFireball, 0, 1000f, cpuPlayer.walkingForwardState),
          new CpuActions(cpuPlayer.waitingState, opponentPlayer.throwFireball, 0, 1000f, cpuPlayer.jumpingState),
          
          new CpuActions(cpuPlayer.waitingState, opponentPlayer.fallingKickState, MIN_KICK_DISTANCE, MAX_JUMP_DISTANCE, cpuPlayer.walkingBackwardState),
          new CpuActions(cpuPlayer.walkingBackwardState, opponentPlayer.fallingKickState, MIN_KICK_DISTANCE, MAX_JUMP_DISTANCE, cpuPlayer.jumpingState),
          new CpuActions(cpuPlayer.waitingState, opponentPlayer.fallingPunchState, MIN_KICK_DISTANCE, MAX_JUMP_DISTANCE, cpuPlayer.walkingBackwardState),
          new CpuActions(cpuPlayer.walkingBackwardState, opponentPlayer.fallingPunchState, MIN_KICK_DISTANCE, MAX_JUMP_DISTANCE, cpuPlayer.jumpingState),
          new CpuActions(cpuPlayer.waitingState, null, 0, MIN_KICK_DISTANCE, cpuPlayer.punchingState),
          
          new CpuActions(cpuPlayer.waitingState, opponentPlayer.throwFireball, 0, MIN_KICK_DISTANCE*2, cpuPlayer.walkingForwardState),

          
          new CpuActions(cpuPlayer.walkingForwardState, null, MIN_JUMP_DISTANCE, MAX_JUMP_DISTANCE, cpuPlayer.jumpingState),

          new CpuActions(cpuPlayer.walkingBackwardState, opponentPlayer.fallingKickState, MIN_KICK_DISTANCE, MAX_JUMP_DISTANCE, cpuPlayer.jumpingState),
          
          new CpuActions(cpuPlayer.fallingState, null, 0, MIN_KICK_DISTANCE, cpuPlayer.fallingKickState),
          
          new CpuActions(null, opponentPlayer.loseState, 0, 1000f, cpuPlayer.winState),
        };
        
        cpuActions = localCpuActions;
    }

    
    @Override
    public void updateCpuActions(float cpuSleep) {
        
        timeCounter += Gdx.graphics.getDeltaTime();
        
        
        if ((timeCounter > cpuSleep ) && (cpuPlayer.getActorState().equals(cpuPlayer.waitingState)) &&  (opponentPlayer.getActorState().equals(opponentPlayer.waitingState))){ 
            timeCounter = 0;
            
            cpuPlayer.setActorState(cpuPlayer.walkingForwardState);
        }
        
        for (int i = 0; i < cpuActions.length; i++) {
            if ((cpuActions[i].cpuActualState == null ) || (cpuActions[i].cpuActualState.equals(cpuPlayer.getActorState()))) {
                if ((cpuActions[i].opponentActualState == null ) || (cpuActions[i].opponentActualState.equals(opponentPlayer.getActorState()))) {
                
                    float opponentDistance = getOpponentDistance();
                    if ((opponentDistance >= cpuActions[i].minDistanceToExecute ) &&(opponentDistance < cpuActions[i].maxDistanceToExecute)) {
                        cpuPlayer.setActorState(cpuActions[i].cpuNewState);
                    }
                    
                }
            }
        }
    }

}
